﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="VedaClientProfile.aspx.cs" Inherits="CRMWeb.Pages.VedaClientProfile" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Veda Credit Check</title>
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/EasyUI/Themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="/Css/CrmStyle.css" />
    <script type="text/javascript" src="/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/EasyUI/jquery.easyui.min.js"></script>
</head>
<body>
    <div id="pnlVedaClientProfile" title="Applicant Credit Check" class="easyui-panel" style="width: auto; height: auto; padding-left: 15px;">
        <input type="hidden" id="hdnVedaResponse" runat="server" />
        <input type="hidden" id="hdnFirstGivenName" runat="server" />
        <input type="hidden" id="hdnFamilyName" runat="server" />
        <input type="hidden" id="hdnGender" runat="server" />
        <input type="hidden" id="hdnDriversLicenceNumber" runat="server" />
        <input type="hidden" id="hdnDateofBirth" runat="server" />
        <input type="hidden" id="hdnStreetNumber" runat="server" />
        <input type="hidden" id="hdnStreetName" runat="server" />
        <input type="hidden" id="hdnSuburb" runat="server" />
        <input type="hidden" id="hdnState" runat="server" />
        <input type="hidden" id="hdnPostCode" runat="server" />
        <br />
        <div>
            <input id="rdoByClientProfile" type="radio" name="rdoByCheck" checked /><span class="auto-style1"><strong>By client profile </strong></span>
        </div>
        <div>
            Please match data with Driver Licence/Passport
        </div>
        <br />
        <div>
            <div class="fitem">
                <label style="width: 30%">Filed</label>
                <label style="width: 60%">Value</label>
            </div>
            <div class="fitem">
                <label style="width: 30%">First Name:</label>
                <input id="txtFirstGivenName" style="width: 40%;" class="easyui-validatebox" name="FirstGivenName" type="text" />
                <input id="chkFirstGivenName" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Last Name:</label>
                <input id="txtFamilyName" style="width: 40%;" class="easyui-validatebox" name="FamilyName" type="text" />
                <input id="chkFamilyName" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Gender:</label>
                <%--change to drop down list for gender --from Wade 20131023--%>
                <select id="cmbGender" data-options="panelHeight:'auto'" class="easyui-combobox" style="width: 95px;">
                        <option  selected="selected" value="Male">Male</option>
                        <option value="Female">Female</option>
                        <option value="">&nbsp</option>
                </select>

              <%--  <input id="txtGender" style="width: 60%;" class="easyui-validatebox" name="Gender" type="text" />--%>

                <input id="chkGender" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Drivers Licence:</label>
                <input id="txtDriversLicenceNumber" style="width: 40%;" class="easyui-validatebox" name="DriversLicenceNumber" type="text" />
                <input id="chkDriversLicenceNumber" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">DOB:</label>
              <%--  <input id="txtDateofBirth" name="draw_down_date" class="easyui-datebox" data-options="formatter:formatLoanDate" style="width: 90px;" />--%>

                <input id="txtDateofBirth" name="draw_down_date" class="easyui-datebox" data-options="formatter:au_formatter,parser:au_parser" style="width: 90px;" />

                <input id="chkDateofBirth" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Residential</label>
            </div>
            <div class="fitem">
                <label style="width: 30%">Street Number:</label>
                <input id="txtStreetNumber" style="width: 40%;" class="easyui-validatebox" name="StreetNumber" type="text" />
                <input id="chkStreetNumber" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Street Name:</label>
                <input id="txtStreetName" style="width: 40%;" class="easyui-validatebox" name="StreetName" type="text" />
                <input id="chkStreetName" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Suburb:</label>
                <input id="txtSuburb" style="width: 40%;" class="easyui-validatebox" name="Suburb" type="text" />
                <input id="chkSuburb" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">State:</label>
                <input id="txtState" style="width: 40%;" class="easyui-validatebox" name="State" type="text" />
                <input id="chkState" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Postcode:</label>
                <input id="txtPostCode" style="width: 40%;" class="easyui-validatebox" name="PostCode" type="text" />
                <input id="chkPostCode" type="checkbox" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Loan Amount:</label>
                <input id="txtLoanAmount" style="width: 40%;" class="easyui-validatebox" name="LoanAmount" type="text" />
            </div>
            <div class="fitem">
                <label style="width: 30%">Our Reference:</label>
                <input id="txtClientReference" style="width: 40%;" class="easyui-validatebox" name="ClientReference" type="text" />
            </div>
            <div class="fitem">
                <label style="width: 71%; text-align: right;">Update Data to Client Profile</label>
                <input id="chkUpdateDatatoClientProfile" type="checkbox" onchange="CheckUncheckClientProfile()" checked />
            </div>
            <div>
                <input id="rdoByVedaFileNo" type="radio" name="rdoByCheck" /><span class="auto-style1"><strong>By Veda File No.</strong></span>
            </div>
            <br />
            <div>
                <div class="fitem">
                    <label style="width: 30%">Veda File No:</label>
                    <input id="txtVedaFileNo" style="width: 40%;" class="easyui-validatebox" name="VedaFileNo" type="text" />
                </div>
            </div>
            <br />
            <div>
                Confirm data are accurate
                <input id="chkOperatorData" type="checkbox" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label><strong>Operator:</strong></label><label id="lblUserName" runat="server"></label>
            </div>
            <br />
            <div id="p1" style="width: 100%; height: auto; text-align: center;">
                <img src="/Media/progress.gif" style="animation: ease-in-out" />
                <br />
                <b>Please wait... </b>
            </div>
            <div style="text-align: center">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="VedaCreditCheck();">Credit Check Now</a>
            </div>
            <div>
                <label id="lblErrorMsg" style="color: red;">
                </label>
            </div>
        </div>
        <br />
    </div>
    <script type="text/javascript">
        function CheckUncheckClientProfile() {
            if ($('#chkUpdateDatatoClientProfile').is(":checked")) {
                $('#chkFirstGivenName').prop('checked', true);
                $('#chkFamilyName').prop('checked', true);
                $('#chkGender').prop('checked', true);
                $('#chkDriversLicenceNumber').prop('checked', true);
                $('#chkDateofBirth').prop('checked', true);
                $('#chkStreetNumber').prop('checked', true);
                $('#chkStreetName').prop('checked', true);
                $('#chkSuburb').prop('checked', true);
                $('#chkState').prop('checked', true);
                $('#chkPostCode').prop('checked', true);
            }
            else {
                $('#chkFirstGivenName').prop('checked', false);
                $('#chkFamilyName').prop('checked', false);
                $('#chkGender').prop('checked', false);
                $('#chkDriversLicenceNumber').prop('checked', false);
                $('#chkDateofBirth').prop('checked', false);
                $('#chkStreetNumber').prop('checked', false);
                $('#chkStreetName').prop('checked', false);
                $('#chkSuburb').prop('checked', false);
                $('#chkState').prop('checked', false);
                $('#chkPostCode').prop('checked', false);
            }
        }

        function formatLoanDate(value, row) {
            if (value == null)
                return value;
            var date = new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return (d < 10 ? ('0' + d) : d) + '/' + (m < 10 ? ('0' + m) : m) + '/' + y;
        }

        function DefaultformatLoanDate(value) {
            dArr = value.split('/');
            return dArr[1] + '/' + dArr[0] + '/' + dArr[2];
        }
        //Australia date format dd/mm/yyyy --From Wade
        function AuDefaultformatLoanDate(value) {
            dArr = value.split('/');
            return dArr[0] + '/' + dArr[1] + '/' + dArr[2];
        }

        function au_formatter(value, row) {
            var date = (value === null) ? new Date() : new Date(value);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return (d < 10 ? ('0' + d) : d) + '/' + (m < 10 ? ('0' + m) : m) + '/' + y;
        }

        function au_parser(s) {
            if (!s) return new Date();

            var ss = (s.split('/'));
            var d = new Number(ss[0]);
            var m = new Number(ss[1]);
            var y = new Number(ss[2]);

            if (!isNaN(d) && !isNaN(m) && !isNaN(y)) {
                return new Date(y, m - 1, d);
            }
            else {
                return new Date();
            }
        }
        //End  --20131023  
        function VedaCreditCheck() {
            if ($('#chkOperatorData').is(":checked")) {
                $('#p1').show();
                var VedaFileNo = $('#txtVedaFileNo').val();
                var FirstGivenName = $('#txtFirstGivenName').val();
                var FamilyName = $('#txtFamilyName').val();
              //  var Gender = $('#txtGender').val();

                var Gender = $('#cmbGender').combobox('getValue');
                var DriversLicenceNumber = $('#txtDriversLicenceNumber').val();

                var DateofBirth = $('#txtDateofBirth').datebox('getValue');
                var StreetNumber = $('#txtStreetNumber').val();
                var StreetName = $('#txtStreetName').val();
                var Suburb = $('#txtSuburb').val();
                var State = $('#txtState').val();
                var PostCode = $('#txtPostCode').val();
                var LoanAmount = $('#txtLoanAmount').val();
                var ClientReference = $('#txtClientReference').val();
                var currentdate = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate();
                var CreatedBy = $('#lblUserName').text();
                var hdnFirstGivenName;
                var hdnFamilyName;
                var hdnGender;
                var hdnDriversLicenceNumber;
                var hdnDateofBirth;
                var hdnStreetNumber;
                var hdnStreetName;
                var hdnSuburb;
                var hdnState;
                var hdnPostCode;
                var hdnLoanAmount;
                var flagByCreditCheck = 0;

                if ($('#rdoByClientProfile').is(":checked"))
                    flagByCreditCheck = 0;
                else
                    flagByCreditCheck = 1;
                if ($('#chkFirstGivenName').is(":checked"))
                    hdnFirstGivenName = $('#txtFirstGivenName').val();
                else
                    hdnFirstGivenName = $('#hdnFirstGivenName').val();

                if ($('#chkFamilyName').is(":checked"))
                    hdnFamilyName = $('#txtFamilyName').val();
                else
                    hdnFamilyName = $('#hdnFamilyName').val();

                if ($('#chkGender').is(":checked"))
                   // hdnGender = $('#txtGender').val();
                    hdnGender = $('#cmbGender').combobox('getValue');
                else
                    hdnGender = $('#hdnGender').val();

                if ($('#chkDriversLicenceNumber').is(":checked"))
                    hdnDriversLicenceNumber = $('#txtDriversLicenceNumber').val();
                else
                    hdnDriversLicenceNumber = $('#hdnDriversLicenceNumber').val();

                if ($('#chkDateofBirth').is(":checked")) {
                    var hdnDateofBirth = $('#txtDateofBirth').datebox('getValue');
                    if (hdnDateofBirth != '')
                        hdnDateofBirth = DefaultformatLoanDate($('#txtDateofBirth').datebox('getValue'));
                }
                else {
                    var hdnDateofBirth = $('#hdnDateofBirth').val();
                    if (hdnDateofBirth != '')
                        hdnDateofBirth = DefaultformatLoanDate($('#hdnDateofBirth').val());
                }

                if ($('#chkStreetNumber').is(":checked"))
                    hdnStreetNumber = $('#txtStreetNumber').val();
                else
                    hdnStreetNumber = $('#hdnStreetNumber').val();

                if ($('#chkStreetName').is(":checked"))
                    hdnStreetName = $('#txtStreetName').val();
                else
                    hdnStreetName = $('#hdnStreetName').val();

                if ($('#chkSuburb').is(":checked"))
                    hdnSuburb = $('#txtSuburb').val();
                else
                    hdnSuburb = $('#hdnSuburb').val();

                if ($('#chkState').is(":checked"))
                    hdnState = $('#txtState').val();
                else
                    hdnState = $('#hdnState').val();

                if ($('#chkPostCode').is(":checked"))
                    hdnPostCode = $('#txtPostCode').val();
                else
                    hdnPostCode = $('#hdnPostCode').val();

                //if ($('#chkLoanAmount').is(":checked"))
                //    hdnLoanAmount = $('#txtLoanAmount').val();
                //else
                //    hdnLoanAmount = $('#hdnLoanAmount').val();
                $.ajax({
                    url: '/WebServices/ApplicantCreditCheck.ashx?method=VedaCreditCheck',
                    contentType: 'application/json; charset=utf-8',
                    data: { 'app_id': getQuerystring('app_id', ''), 'ContactID': getQuerystring('ContactID', ''), 'FirstGivenName': FirstGivenName, 'FamilyName': FamilyName, 'Gender': Gender, 'DriversLicenceNumber': DriversLicenceNumber, 'DateofBirth': DateofBirth, 'StreetNumber': StreetNumber, 'StreetName': StreetName, 'Suburb': Suburb, 'State': State, 'PostCode': PostCode, 'LoanAmount': LoanAmount, 'ClientReference': ClientReference, 'CreatedDate': currentdate, 'CreatedBy': CreatedBy, 'VedaFileNo': VedaFileNo, 'flagByCreditCheck': flagByCreditCheck },
                    success: function (data) {
                        if (data.search(".xml") != -1) {
                            if (flagByCreditCheck == 0) {
                                $.ajax({
                                    url: '/WebServices/ApplicantCreditCheck.ashx?method=UpdateClientProfile',
                                    contentType: 'application/json; charset=utf-8',
                                    data: { 'app_id': getQuerystring('app_id', ''), 'ContactID': getQuerystring('ContactID', ''), 'FirstGivenName': hdnFirstGivenName, 'FamilyName': hdnFamilyName, 'Gender': hdnGender, 'DriversLicenceNumber': hdnDriversLicenceNumber, 'DateofBirth': hdnDateofBirth, 'StreetNumber': hdnStreetNumber, 'StreetName': hdnStreetName, 'Suburb': hdnSuburb, 'State': hdnState, 'PostCode': hdnPostCode },
                                    success: function (data) {
                                    }
                                });
                            }
                            var desc = 'Check the credit information :' + data;
                            var currentDate = new Date();
                            var HistoryDate = currentDate.getMonth() + 1 + "/" + currentDate.getDate() + "/" + currentDate.getFullYear();
                            var currentTime = new Date();
                            var HistoryTime = currentTime.getHours() + ':' + currentTime.getMinutes() + ':' + currentTime.getSeconds();;
                            var Action = 'CreditCheck';
                            var Operator = $('#lblUserName').text();
                            // insert to Contact_history
                            $.ajax({
                                type: "Post",
                                url: "/WebServices/History.ashx?method=saveNewHistory",
                                data: { HistoryType: 'Contact', contactid: getQuerystring('ContactID', ''), hdate: HistoryDate, htime: HistoryTime, action: Action, user: Operator, description: desc, appid: '0' },
                                success: function (result) {
                                }
                            });
                            // insert to Application_history
                            $.ajax({
                                type: "Post",
                                data: { HistoryType: 'Application', contactid: '0', hdate: HistoryDate, htime: HistoryTime, action: Action, user: Operator, description: desc, appid: getQuerystring('app_id', '') },
                                url: "/WebServices/History.ashx?method=saveNewHistory",
                                success: function (result) {
                                }
                            });
                            setTimeout(function () {
                                $('#p1').hide();
                                window.close();
                                window.opener.location.reload();
                                //$('#MainTab').tabs('select', 'Credit Check');
                                var myWindow = window.open('/Pages/Application/VedaResponseData/' + data, '_blank');
                                myWindow.focus();
                            }, 100);
                        }
                        else {
                            $('#p1').hide();
                            $('#lblErrorMsg').text(data.toString());
                        }
                    },
                    error: function (xhr, errorType, exception) {
                        var errorMessage = exception || xhr.statusText;
                        $('#p1').hide();
                        $('#lblErrorMsg').text('There was an error : ' + errorMessage);
                    }
                });
            }
            else {
                $.messager.alert('Veda Check', 'Select \'Confirm data are accurate\' to continue');
            }
        }

        $(document).ready(function () {
            $('#p1').hide();
            CheckUncheckClientProfile();
            window.onresize = function () {
                $('#pnlVedaClientProfile').panel('resize', {
                    width: window.innerWidth,
                    height: window.innerHeight
                });
            }
            $.ajax({
                url: '/WebServices/ApplicantCreditCheck.ashx?method=GetSingleClientDetalis',
                contentType: 'application/json; charset=utf-8',
                data: { 'ContactID': getQuerystring('ContactID', ''), 'app_id': getQuerystring('app_id', '') },
                success: function (data) {
                    $.each(eval(data.replace(/[\r\n]/, '')), function (i, rec) {
                        $('#txtVedaFileNo').val(getQuerystring('VedafileNO', ''));
                        $('#txtFirstGivenName').val(rec.FirstName);
                        $('#txtFamilyName').val(rec.SurName);
                       // $('#txtGender').val(rec.Gender);
                        $('#cmbGender').combobox('setValue', rec.Gender);
                        $('#txtDriversLicenceNumber').val(rec.DriverLicense);
                       // $('#txtDateofBirth').datebox('setValue', formatLoanDate(rec.DateBirth, null));
                        $('#txtDateofBirth').datebox('setValue', au_formatter(rec.DateBirth, null));
                        $('#txtStreetNumber').val(rec.StreetNo);
                        $('#txtStreetName').val(rec.Street);
                        $('#txtSuburb').val(rec.Suburb);
                        $('#txtState').val(rec.State);
                        $('#txtPostCode').val(rec.PostCode);
                        $('#txtClientReference').val(rec.SurName.substr(0, 4) + getQuerystring('ContactID', ''));
                        $('#txtLoanAmount').val(rec.LoanAmount);
                        //Insert Data in Hidden Field
                        $('#hdnFirstGivenName').val(rec.FirstName);
                        $('#hdnFamilyName').val(rec.SurName);
                        $('#hdnGender').val(rec.Gender);
                        $('#hdnDriversLicenceNumber').val(rec.DriverLicense);
                       // $('#hdnDateofBirth').val(formatLoanDate(rec.DateBirth, null));
                        $('#hdnDateofBirth').val(au_formatter(rec.DateBirth, null));
                        $('#hdnStreetNumber').val(rec.StreetNo);
                        $('#hdnStreetName').val(rec.Street);
                        $('#hdnSuburb').val(rec.Suburb);
                        $('#hdnState').val(rec.State);
                        $('#hdnPostCode').val(rec.PostCode);
                    });
                }
            });
            $('#pnlVedaClientProfile').panel('resize', {
                width: window.innerWidth,
                height: window.innerHeight
            });
        });

        function getQuerystring(key, defaultValue) {
            if (defaultValue == null) defaultValue = "";
            key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
            var qs = regex.exec(window.location.href);
            if (qs == null)
                return defaultValue;
            else {
                return qs[1];
            }
        }
    </script>
</body>
</html>
